-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relayer/Contract: Move decimal conversion from relayer code to contract code. #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 11 files reviewed, 10 unresolved discussions (waiting on @keyleu, @miladz68, @wojtek-coreum, and @ysv)
contract/src/contract.rs
line 238 at r1 (raw file):
if sending_precision > decimals.try_into().unwrap() { return Err(ContractError::TokenSendingPrecisionTooHigh {}); }
Those 2 functions should be moved to separate function and used for both XRPL and coreum tokens. Since now you don't validate the sending_precision <= decimals
for the XRPL token, but should.
Code quote:
if !(MIN_SENDING_PRECISION..=MAX_SENDING_PRECISION).contains(&sending_precision) {
return Err(ContractError::InvalidSendingPrecision {});
}
if sending_precision > decimals.try_into().unwrap() {
return Err(ContractError::TokenSendingPrecisionTooHigh {});
}
contract/src/contract.rs
line 797 at r1 (raw file):
to_json_binary(&query_coreum_tokens(deps, offset, limit)?) } QueryMsg::CoreumTokenByXRPLCurrency { xrpl_currency } => {
We don't need that query anymore.
integration-tests/coreum/contract_client_test.go
line 1105 at r1 (raw file):
issueFee := chains.Coreum.QueryAssetFTParams(ctx, t).IssueFee // TODO(dzmitryhil) Change amount in Evidence from sdkmath.Int to a different type to allow sending bigger amounts
The sdkmath.Int
is the max value supported by the cosmos SDK. I guess your issue here is the way you create it.
So use the function to do the sdk.Int creation, and return back please previous amounts we used in the test. integrationtests.ConvertStringWithDecimalsToSDKInt(t, "99", 11)
= 9900000000000
relayer/processes/xrpl_tx_observer.go
line 132 at r1 (raw file):
// for the coreum originated tokens we need to use toke decimals, but for the XRPL they are static if o.cfg.BridgeXRPLAddress.String() == deliveredXRPLAmount.Issuer.String() { coreumToken, err := o.contractClient.GetCoreumTokenByXRPLCurrency(ctx, stringCurrency)
Remvoe please GetCoreumTokenByXRPLCurrency
form model.go/ContractClient
and regenerate mocks make mockgen
. Also remove it from the coreum/contract.go
since we don't need it anymore.
relayer/processes/xrpl_tx_observer.go
line 136 at r1 (raw file):
return errors.Wrapf(err, "faild to get XRPL token for the XRPL to coreum transfer") } coreumAmount, err = ConvertCoreumOriginatedTokenXRPLAmountToCoreumAmount(*deliveredXRPLAmount, coreumToken.Decimals)
Remvoe the ConvertCoreumOriginatedTokenXRPLAmountToCoreumAmount
and ConvertCoreumOriginatedTokenCoreumAmountToXRPLAmount
functions and corresponding unit tests.
relayer/processes/xrpl_tx_observer_test.go
line 155 at r1 (raw file):
Issuer: bridgeXRPLAddress.String(), Currency: stringCurrency, Amount: sdkmath.NewIntWithDecimal(999, int(15)),
Use XRPLIssuedCurrencyDecimals
inseated of 15
relayer/processes/xrpl_tx_submitter_test.go
line 199 at r1 (raw file):
}, { name: "register_signature_for_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx",
register_signature_for_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx -> register_signature_for_coreum_to_XRPL_token_transfer_payment_tx
(and remove test-data function it is not needed anymore )
relayer/processes/xrpl_tx_submitter_test.go
line 224 at r1 (raw file):
}, { name: "submit_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx_with_filtered_signature",
submit_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx_with_filtered_signature -> submit_coreum_to_XRPL_token_transfer_payment_tx_with_filtered_signature
Also do the corresponding renaming for variables and function, since it tearms of the code now we don't have any difference between the XRPL or coreum token.
// XRPLOriginated -> remove comment
coreumToXRPLXRPLOriginatedTokenTransferOperation, -> rename
coreumToXRPLXRPLOriginatedTokenTransferOperationWithSignatures, -> rename
coreumToXRPLXRPLOriginatedTokenTransferOperationValidSigners := buildCoreumToXRPLXRPLOriginatedTokenTransferTestData(t, xrplTxSigners, bridgeXRPLAddress, contractRelayers) -> rename
relayer/processes/xrpl_tx_submitter_test.go
line 252 at r1 (raw file):
}, { name: "register_signature_for_coreum_to_XRPL_Coreum_originated_token_transfer_payment_tx",
You don't need this use case anymore since it is duplicated now, remove it.
relayer/processes/xrpl_tx_submitter_test.go
line 277 at r1 (raw file):
}, { name: "submit_coreum_to_XRPL_Coreum_originated_token_transfer_payment_tx_with_filtered_signature",
You don't need this use case anymore since it is duplicated now, remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 17 files reviewed, 10 unresolved discussions (waiting on @dzmitryhil, @miladz68, @wojtek-coreum, and @ysv)
contract/src/contract.rs
line 238 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Those 2 functions should be moved to separate function and used for both XRPL and coreum tokens. Since now you don't validate the
sending_precision <= decimals
for the XRPL token, but should.
Done.
contract/src/contract.rs
line 797 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
We don't need that query anymore.
Removed.
integration-tests/coreum/contract_client_test.go
line 1105 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
The
sdkmath.Int
is the max value supported by the cosmos SDK. I guess your issue here is the way you create it.So use the function to do the sdk.Int creation, and return back please previous amounts we used in the test.
integrationtests.ConvertStringWithDecimalsToSDKInt(t, "99", 11)
= 9900000000000
Understood, was confused because newInt only returns uint64 but this one can return up to 256.
Changed it and now it's fine. thx
relayer/processes/xrpl_tx_observer.go
line 132 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Remvoe please
GetCoreumTokenByXRPLCurrency
formmodel.go/ContractClient
and regenerate mocksmake mockgen
. Also remove it from thecoreum/contract.go
since we don't need it anymore.
Done
relayer/processes/xrpl_tx_observer.go
line 136 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Remvoe the
ConvertCoreumOriginatedTokenXRPLAmountToCoreumAmount
andConvertCoreumOriginatedTokenCoreumAmountToXRPLAmount
functions and corresponding unit tests.
Done
relayer/processes/xrpl_tx_observer_test.go
line 155 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Use
XRPLIssuedCurrencyDecimals
inseated of15
Changed.
relayer/processes/xrpl_tx_submitter_test.go
line 199 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
register_signature_for_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx -> register_signature_for_coreum_to_XRPL_token_transfer_payment_tx
(and remove test-data function it is not needed anymore )
Done.
relayer/processes/xrpl_tx_submitter_test.go
line 224 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
submit_coreum_to_XRPL_XRPL_originated_token_transfer_payment_tx_with_filtered_signature -> submit_coreum_to_XRPL_token_transfer_payment_tx_with_filtered_signature
Also do the corresponding renaming for variables and function, since it tearms of the code now we don't have any difference between the XRPL or coreum token.
// XRPLOriginated -> remove comment coreumToXRPLXRPLOriginatedTokenTransferOperation, -> rename coreumToXRPLXRPLOriginatedTokenTransferOperationWithSignatures, -> rename coreumToXRPLXRPLOriginatedTokenTransferOperationValidSigners := buildCoreumToXRPLXRPLOriginatedTokenTransferTestData(t, xrplTxSigners, bridgeXRPLAddress, contractRelayers) -> rename
Unified everything.
relayer/processes/xrpl_tx_submitter_test.go
line 252 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
You don't need this use case anymore since it is duplicated now, remove it.
Removed.
relayer/processes/xrpl_tx_submitter_test.go
line 277 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
You don't need this use case anymore since it is duplicated now, remove it.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 17 files reviewed, 11 unresolved discussions (waiting on @keyleu, @miladz68, @wojtek-coreum, and @ysv)
integration-tests/coreum/contract_client_test.go
line 1158 at r2 (raw file):
sendingAmount: integrationtests.ConvertStringWithDecimalsToSDKInt(t, "1.15567", 1), wantReceivedAmount: integrationtests.ConvertStringWithDecimalsToSDKInt(t, "1", 1), xrplSendingAmount: sdkmath.NewInt(1_000_000_000_000_000),
sdkmath.NewIntWithDecimal ?
integration-tests/coreum/contract_client_test.go
line 1166 at r2 (raw file):
maxHoldingAmount: highMaxHoldingAmount, sendingAmount: integrationtests.ConvertStringWithDecimalsToSDKInt(t, "0.9999", 2), xrplSendingAmount: sdkmath.NewInt(999_900_000_000_000),
sdkmath.NewIntWithDecimal ?
integration-tests/coreum/contract_client_test.go
line 1193 at r2 (raw file):
maxHoldingAmount: highMaxHoldingAmount, sendingAmount: integrationtests.ConvertStringWithDecimalsToSDKInt(t, "99.9999", 6), xrplSendingAmount: sdkmath.NewInt(99_999_900_000_000_000),
sdkmath.NewIntWithDecimal ?
integration-tests/coreum/contract_client_test.go
line 1947 at r2 (raw file):
require.Equal(t, operationType.Currency, registeredCoreumOriginatedToken1.XRPLCurrency) // XRPL DECIMALS (15) - TOKEN DECIMALS (5) = 10 require.Equal(t, operationType.Amount, amountToSendOfToken1.Mul(sdk.NewInt(10_000_000_000)))
sdkmath.NewIntWithDecimal ?
integration-tests/coreum/contract_client_test.go
line 1997 at r2 (raw file):
require.Equal(t, operationType.Currency, registeredCoreumOriginatedToken2.XRPLCurrency) // XRPL DECIMALS (15) - TOKEN DECIMALS (6) = 9 require.Equal(t, operationType.Amount, amountToSendOfToken2.Mul(sdk.NewInt(1_000_000_000)))
sdkmath.NewIntWithDecimal ?
relayer/processes/xrpl_tx_observer.go
line 136 at r1 (raw file):
Previously, keyleu (Keyne) wrote…
Done
Still see ConvertCoreumOriginatedTokenCoreumAmountToXRPLAmount
relayer/processes/xrpl_tx_observer.go
line 129 at r2 (raw file):
stringCurrency := xrpl.ConvertCurrencyToString(deliveredXRPLAmount.Currency) coreumAmount, err := ConvertXRPLOriginatedTokenXRPLAmountToCoreumAmount(*deliveredXRPLAmount)
The function name is wrong now.
- ConvertXRPLOriginatedTokenXRPLAmountToCoreumAmount -> ConvertXRPLAmountToCoreumAmount
- ConvertXRPLOriginatedTokenCoreumAmountToXRPLAmount -> ConvertXRPLCoreumAmountToXRPLAmount
And test names for it as well
relayer/processes/xrpl_tx_submitter_test.go
line 199 at r1 (raw file):
Previously, keyleu (Keyne) wrote…
Done.
Still see it.
relayer/processes/xrpl_tx_submitter_test.go
line 224 at r1 (raw file):
Previously, keyleu (Keyne) wrote…
Unified everything.
Check please, probably you didn't push. Since I don't see changes.
relayer/processes/xrpl_tx_submitter_test.go
line 252 at r1 (raw file):
Previously, keyleu (Keyne) wrote…
Removed.
Still see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 17 files reviewed, 11 unresolved discussions (waiting on @dzmitryhil, @miladz68, @wojtek-coreum, and @ysv)
integration-tests/coreum/contract_client_test.go
line 1158 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
sdkmath.NewIntWithDecimal ?
Changed.
integration-tests/coreum/contract_client_test.go
line 1166 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
sdkmath.NewIntWithDecimal ?
Changed.
integration-tests/coreum/contract_client_test.go
line 1193 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
sdkmath.NewIntWithDecimal ?
Changed.
integration-tests/coreum/contract_client_test.go
line 1947 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
sdkmath.NewIntWithDecimal ?
Changed
integration-tests/coreum/contract_client_test.go
line 1997 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
sdkmath.NewIntWithDecimal ?
Changed.
relayer/processes/xrpl_tx_observer.go
line 136 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Still see
ConvertCoreumOriginatedTokenCoreumAmountToXRPLAmount
Right, I removed them in one place and not others. I was confused with so many different files. Removed now.
relayer/processes/xrpl_tx_observer.go
line 129 at r2 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
The function name is wrong now.
- ConvertXRPLOriginatedTokenXRPLAmountToCoreumAmount -> ConvertXRPLAmountToCoreumAmount
- ConvertXRPLOriginatedTokenCoreumAmountToXRPLAmount -> ConvertXRPLCoreumAmountToXRPLAmount
And test names for it as well
Done, Changed.
relayer/processes/xrpl_tx_submitter_test.go
line 199 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Still see it.
It's removed.
relayer/processes/xrpl_tx_submitter_test.go
line 224 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Check please, probably you didn't push. Since I don't see changes.
I unified. Check again.
relayer/processes/xrpl_tx_submitter_test.go
line 252 at r1 (raw file):
Previously, dzmitryhil (Dzmitry Hil) wrote…
Still see it.
It's removed, check again please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 17 files reviewed, all discussions resolved (waiting on @miladz68, @wojtek-coreum, and @ysv)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 11 files at r1, 8 of 11 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @wojtek-coreum and @ysv)
Description
Reviewers checklist:
Authors checklist
This change is